<?php


namespace App\Admin\Actions\Tools;


use App\Admin\Actions\BatchAction;
use App\Models\AdminUser;
use App\Transverse;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Http\Request;

class TransverseTagBatchAction extends BatchAction
{
    protected $selector = '.transverse-tag-posts';

    public function handle(Collection $collection, Request $request)
    {
        $tag = $request->get('tag', 0);
        foreach ($collection as $model) {
            if ($model instanceof Transverse) {
                $model->tag = $tag;
                $model->save();
            }
        }
        return $this->response()->success('操作成功！')->refresh();
    }


    public function form()
    {
        $this->radio('tag', '技术合同登记')->options(['否', '是'])->default(1)->required();
    }

    public function html()
    {
        return "<a class='transverse-tag-posts btn btn-sm btn-primary'>技术合同登记</a>";
    }

    public function authorize(AdminUser $user, Collection $collection)
    {
        return $user->role_type == 1;
    }

}
